/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package iteracon.generator.iterator;

import java.util.Iterator;

/**
 *
 * @author martin
 */
public class FromToStepIter implements Iterator<Integer>{
    private int _to,
                      _step,
                      _now;

    public FromToStepIter(int from, int to, int step){
      _now=from;
      _to=to;
      _step=step;
    }
    
    @Override
    public boolean hasNext() {
      if (_step<0)
        return _now+_step >= _to;
      return _now+_step < _to;
    }

    @Override
    public Integer next() {
      int tmp = _now;
      _now = _now + _step;
      return tmp;
    }

    @Override
    public void remove() {
      throw new UnsupportedOperationException("Immutable");
    }
    
  }
